/**
 * 人才库-加入/移出高级库
 */
import React, { memo, useState } from 'react';
import { withRouter } from 'umi';
import AuthComponent from '@/utils/auth/AuthComponent';
import { Icon } from '../../components';
import TalentsJoinSeniorModal from './TalentsJoinSeniorModal';

function TalentsJoinSeniorOperate({ disabled = false, operateType, onRefresh, tooltipTitle, ...rest }) {
    const [visible, setVisible] = useState(false);
    const [title] = useState(operateType === 'add' ? '加入高级库' : '移出高级库');
    return (
        <AuthComponent code={operateType === 'add' ? 'office:recruitment:talentsManagement:addSeniorList' : 'office:recruitment:talentsManagement:removeSeniorList'}>
            <Icon
                type={operateType === 'add' ? 'listfunction_addtohighstock_icon_default' : 'listfunction_removefromhighstock_icon_defaultbeifen'}
                title={tooltipTitle || title}
                disabled={disabled}
                onClick={() => {
                    setVisible(true);
                }} />
            <TalentsJoinSeniorModal
                title={title}
                operateType={operateType}
                visible={visible}
                onCancel={() => { setVisible(false) }}
                onOk={() => {
                    setVisible(false);
                    onRefresh();
                }}
                {...rest}
            />
        </AuthComponent>
    );
}
export default withRouter(memo(TalentsJoinSeniorOperate));
